package com.terrynoya.fight.util
{
	import com.terrynoya.fight.emuns.Axis;
	import com.terrynoya.fight.emuns.Facing;
	import com.terrynoya.fight.emuns.HelperType;
	import com.terrynoya.fight.emuns.HitAnimationType;
	import com.terrynoya.fight.emuns.MoveType;
	import com.terrynoya.fight.emuns.PhysicsEnum;
	import com.terrynoya.fight.emuns.PositionType;
	import com.terrynoya.fight.emuns.StateTypeEnum;
	import com.terrynoya.geom.MVector2D;

	public class Misc
	{
		public static function getOffset(location:MVector2D,facing:int,offset:MVector2D):MVector2D
		{
			var outPut:MVector2D = location.add(new MVector2D(0,offset.y));
			if(facing == Facing.RIGHT)
			{
				outPut.x += offset.x;
				return outPut;
			}
			
			if(facing == Facing.LEFT)
			{
				outPut.x -= offset.x;
				return outPut;
			}
			return location.clone();
		}
		
		public static function flipFacing(facing:int):int
		{
			if(facing == Facing.LEFT)
			{
				return Facing.RIGHT;
			}
			else if(facing == Facing.RIGHT)
			{
				return Facing.LEFT;
			}
			else
			{
				return 0;
			}
		}
		
		public static function getVelocity(txt:String):MVector2D
		{
			if(txt == null)
			{
				return new MVector2D();
			}
			var arr:Array = txt.split(",");
			if(arr.length == 1)
			{
				return new MVector2D(arr[0],0);
			}
			else if(arr.length == 2)
			{
				return new MVector2D(arr[0],arr[1]);
			}
			else
			{
				return new MVector2D();
			}
		}
		
		public static function getPhysicsType(value:String):int
		{
			var rlt:int = PhysicsEnum.NONE;
			switch(value.toLowerCase())
			{
				case "s":
				{
					rlt = PhysicsEnum.Standing;
					break;
				}
				case "a":
				{
					rlt = PhysicsEnum.Airborne;
					break;
				}
				case "c":
				{
					rlt = PhysicsEnum.Crouching;
					break;
				}
				case "u":
				{
					rlt = PhysicsEnum.Unchanged;
					break;
				}
			}
			return rlt;
			
		}
		
		public static function getMoveType(value:String):int
		{
			var rlt:int = MoveType.None;
			switch(value.toLowerCase())
			{
				case "h":
				{
					rlt = MoveType.BeingHit;
					break;
				}
				case "a":
				{
					rlt = MoveType.Attack;
					break;
				}
				case "i":
				{
					rlt = MoveType.Idle;
					break;
				}
			}
			return rlt;
		}
		
		public static function getHitAnimType(value:String):int
		{
			switch(value.toLowerCase())
			{
				case "hard":
				{
					return HitAnimationType.Hard;
					break;
				}
				case "light":
				{
					return HitAnimationType.Light;
					break;
				}
				case "medium":
				{
					return HitAnimationType.Medium;
					break;
				}
				case "back":
				{
					return HitAnimationType.Back;
					break;
				}
				case "diagup":
				{
					return HitAnimationType.DiagUp;
					break;
				}
				case "up":
				{
					return HitAnimationType.Up;
					break;
				}
				default:
				{
					return HitAnimationType.None;
					break;
				}
			}
		}
		
		public static function getStateType(value:String):int
		{
			var rlt:int = StateTypeEnum.NONE;
			switch(value.toLowerCase())
			{
				case "s":
				{
					rlt = StateTypeEnum.Standing;
					break;
				}
				case "a":
				{
					rlt = StateTypeEnum.Airborne;
					break;
				}
				case "c":
				{
					rlt = StateTypeEnum.Crouching;
					break;
				}
				case "u":
				{
					rlt = StateTypeEnum.Unchanged;
					break;
				}
			}
			return rlt;
		}
		
		public static function getAixs(value:String):int
		{
			var axis:int = Axis.None;
			switch(value)
			{
				case "x":
				{
					axis = Axis.X;
					break;
				}
				case "y":
				{
					axis = Axis.Y;
					break;
				}
			}
			return axis;
		}
		
		public static function getPositionType(value:String):int
		{
			var rlt:int = PositionType.None;
			switch(value.toLowerCase())
			{
				case "p1":
				{
					rlt = PositionType.P1;
					break;
				}
				case "p2":
				{
					rlt = PositionType.P2;
					break;
				}
				case "front":
				{
					rlt = PositionType.Front;
					break;
				}
				case "back":
				{
					rlt = PositionType.Back;
					break;
				}
				case "left":
				{
					rlt = PositionType.Left;
					break;
				}
				case "right":
				{
					rlt = PositionType.Right;
					break;
				}
			}
			return rlt;
		}
		
		public static function getHelperType(value:String):int
		{
			var rlt:int = HelperType.Normal;
			switch(value.toLowerCase())
			{
				case "normal":
				{
					rlt = HelperType.Normal;
					break;
				}
				case "player":
				{
					rlt = HelperType.Player;
					break;
				}
				case "projectile":
				{
					rlt = HelperType.Projectile;
					break;
				}
			}
			return rlt;
		}
		
		public static function intToBoolean(value:int):Boolean
		{
			if(value == 0)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		public static function clamp(value:Number,min:Number,max:Number):Number
		{
			return Math.max(min,Math.min(value,max));
		}
		
		
	}
}